package day240607.hw;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.Properties;

public class App {
    public static void main(String[] args) throws Exception {
        // 读取配置文件
        Properties properties = new Properties();
        File file = new File("ice1/src/day240607/hw/config.properties");
        properties.load(new FileInputStream(file));
        System.out.println(properties);
        System.out.println("配置文件读取成功");
        System.out.println("===== ===== =====");

        //下载
        Downloader downloader = getDownloader(properties.getProperty("downloader"));
        String html = downloader.downloader(properties.getProperty("url"));
        System.out.println("网页内容下载完成");
        System.out.println("===== ===== =====");

        //解析
        Parser parser = getParser(properties.getProperty("parser"));
        List<Content> result = parser.parser(html);
        System.out.println(result);
        System.out.println("网页内容解析完成");
        System.out.println("===== ===== =====");
        //
        Storage storage = getStorage(properties.getProperty("storage"));
        storage.storage(result);
        System.out.println("网页内容存储完成");
        //
        Store Store = getStore(properties.getProperty("Store"));
        Store.store(result);
        System.out.println("网页内容通知完成");


        // 存储模块/持久化模块/存到文件或者简单的控制台输出 （每个模块都应该思考它的输入是什么，输出是什么）
        // 面向抽象编程，从更高的角度思考问题，进行规划

        // 通知模块（跟上面的思考过程一样）

        // 总体目标：复习当前阶段的所有核心知识
        //         能够写出漂亮、稳定、可扩展的代码...
    }

    private static Downloader getDownloader(String downloader) {
        return MyReflectionUtil.getInstance(downloader);
    }

    private static Parser getParser (String parser){
            return MyReflectionUtil.getInstance(parser);
        }
    private static Storage getStorage(String storage) {
        return MyReflectionUtil.getInstance(storage);}
    private static Store getStore(String store) {return MyReflectionUtil.getInstance(store);}
    }
